package com.cy.sys.log.service.impl;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.cy.sys.log.Dao.SysLogDao;
import com.cy.sys.log.pojo.pageObject;
import com.cy.sys.log.service.logService;
import com.cy.sys.log.service.exception.ServiceException;
import com.cy.sys.pojo.SysLog;
@Service
public class SysLogServieimpl implements logService{
	@Autowired
	private SysLogDao syslog;
	
	@Async	//此注解表示这个方法有spring框架提供的一个线程运行底层回创建一个线程池给我们分配用于工作线程
	@Override
	@Transactional(propagation = Propagation.REQUIRES_NEW)//运行在新的事务
	public void saveLogObject(SysLog syslogs) {
		//模拟延迟操作
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		syslog.saveLogObject(syslogs);
	}
	
	//差一个删除
	@Override
	public pageObject<SysLog> findpageObject(String username, Integer pageCurrent) {
		//查询总页数
		if(pageCurrent==null||pageCurrent<1)
			throw new IllegalArgumentException("页码值不正确");
			
		int rowCount = syslog.getrowConnt(username);	
		
		if(rowCount==0)
			throw new ServiceException("没有找到你的信息");
		int pageSize = 5;
		
		int pageCount = (pageCurrent-1)*pageSize;
		
		List<SysLog> recosd = syslog.getfindObject(username, pageCount, pageSize);
		
		return new pageObject<>(pageSize, rowCount, pageCurrent, recosd);
	}

}
